package com.tobie.info.controller;

import com.tobie.info.entity.FlightEntity;
import com.tobie.info.service.IFlightService;
import com.tobie.info.util.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lc
 * @Date 2023/11/17 9:56
 * @注释 航班信息页面控制器
 */
@Slf4j
@RestController
@RequestMapping("/flight")
public class  FlightController {

    @Resource
    private IFlightService flightService;

    @GetMapping("/getFlight/{leaveCity}/{arriveCity}")
    public ResultVo<List<FlightEntity>> getFlightByLeaveCityAndArriveCity
            (@PathVariable("leaveCity") String leaveCity,
             @PathVariable("arriveCity") String arriveCity){

        log.info("起始地："+leaveCity + ",目的地：" + arriveCity);
        List<FlightEntity> flightEntities = flightService.getFlightByLeaveCityAndArriverCity
                (leaveCity,arriveCity);
        return ResultVo.success(flightEntities);
    }

    @GetMapping("/getAllFlight")
    public ResultVo<List<FlightEntity>> getAllFlight(){
        return ResultVo.success(flightService.getAllFlight());
    }
}
